//
//  WWDeliveryAddressView.m
//  Shopping
//
//  Created by 张世敏 on 16/8/20.
//  Copyright © 2016年 张湾湾. All rights reserved.
//

#import "WWDeliveryAddressView.h"

@interface WWDeliveryAddressView()

/** 收货人 **/
@property (nonatomic, strong) UILabel *consigneeLabel;
/** 电话 **/
@property (nonatomic, strong) UILabel *phoneNumberLabel;
/** 收货地址 **/
@property (nonatomic, strong) UILabel *addressLabel;



@end

@implementation WWDeliveryAddressView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    
    return self;
}


#pragma mark - 设置界面
-(void)setupUI{
    // 添加3组label
    self.consigneeLabel = [self addLabel];
    self.phoneNumberLabel = [self addLabel];
    self.addressLabel = [self addLabel];
    
    UILabel *leftConsigneeLabel = [self addLabel];
    UILabel *leftPhoneNumberLabel = [self addLabel];
    UILabel *leftAddressLabel = [self addLabel];
    
    leftConsigneeLabel.text = @"收  货  人";
    leftPhoneNumberLabel.text = @"电       话";
    leftAddressLabel.text = @"收货地址";
    // 测试数据
    self.consigneeLabel.text = @"维尼的小熊 先生";
    self.phoneNumberLabel.text = @"18833331111";
    self.addressLabel.text = @"人民大会堂9527办公室";

    // 添加右侧的修改按钮
    UIButton *modifyBtn = [self addButton];
    
    // 布局
    [leftConsigneeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(10);
        make.leading.equalTo(17);
        make.width.equalTo(50);
    }];
    
    [self.consigneeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(leftConsigneeLabel);
        make.leading.equalTo(leftConsigneeLabel.trailing).offset(15);
    }];
    
    [leftPhoneNumberLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(0);
        make.leading.equalTo(leftConsigneeLabel);
        make.width.equalTo(50);
    }];
    
    [self.phoneNumberLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(leftPhoneNumberLabel);
        make.leading.equalTo(leftPhoneNumberLabel.trailing).offset(15);
    }];
    
    [leftAddressLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(leftPhoneNumberLabel.bottom).offset(10);
        make.leading.equalTo(leftPhoneNumberLabel);
        make.width.equalTo(50);
    }];
    
    [self.addressLabel makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(-10);
        make.leading.equalTo(leftAddressLabel.trailing).offset(15);
    }];
    
    [modifyBtn makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(0);
        make.trailing.offset(-30);
    }];
}


#pragma mark - 点击收货地址修改按钮
-(void)modifyAddress:(UIButton *)sender{
    NSLog(@"收货地址修改按钮点击了");
}


/** 添加文字label **/
-(UILabel *)addLabel{
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont systemFontOfSize:12];
    [self addSubview:label];
    
    return label;
}


/** 添加按钮 **/
-(UIButton *)addButton{
    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:@"修改" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [btn addTarget:self action:@selector(modifyAddress:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    
    return btn;
}

@end
